/* Government failure model */

set more off

use "c:\Data\Imf\IMFdata1.dta", clear
drop baltic balkan casia restussr upto1993 ParlXel2 ExecXel2 USODA oecd IMFlag CHRSL1 CHERL1 CHDCL1 CPIL1 CPIL6 CPILSQ CHDCLSQ CHERLSQ AVGCHDC AVGCPI AVGCHER IMFQuota IMFParts IMFnump IMFseatl IMFParl2 IMFdem IMFUSAID IMFUSODA IMFoecd IMFCHRSL IMFCHDCL IMFCPIL1 IMFCPIL6 _st _d _t _t0 IMFecon IMFmil pfall IMFpfall rfall IMFrfall
quietly run c:\Data\Imf\variables.do

stset Govdur, failure( Govfall) id(govid)
streg baltic balkan casia restussr upto1993 interim numpart seatlar Partisan war Executiv FHdem ParlXel2 ExecXel2 IMFlag, dist(w) robust 

predict pfall, hazard
gen IMFpfall = IMFstat*pfall
gen rfall=Partisan*pfall
gen IMFrfall=rfall*IMFstat

matrix b1=e(b)
matrix v1=e(V)
save "c:\Data\Imf\IMFdata1.dta", replace

use "c:\Data\Imf\IMFdata2.dta", clear
drop baltic balkan casia restussr upto1993 ParlXel2 ExecXel2 USODA oecd IMFlag CHRSL1 CHERL1 CHDCL1 CPIL1 CPIL6 CPILSQ CHDCLSQ CHERLSQ AVGCHDC AVGCPI AVGCHER IMFQuota IMFParts IMFnump IMFseatl IMFParl2 IMFdem IMFUSAID IMFUSODA IMFoecd IMFCHRSL IMFCHDCL IMFCPIL1 IMFCPIL6 _st _d _t _t0 IMFecon IMFmil pfall IMFpfall rfall IMFrfall
quietly run c:\Data\Imf\variables.do

stset Govdur, failure( Govfall) id(govid)
streg baltic balkan casia restussr upto1993 interim numpart seatlar Partisan war Executiv FHdem ParlXel2 ExecXel2 IMFlag, dist(w) robust 

predict pfall, hazard
gen IMFpfall = IMFstat*pfall
gen rfall=Partisan*pfall
gen IMFrfall=rfall*IMFstat

matrix b2=e(b)
matrix v2=e(V)
save "c:\Data\Imf\IMFdata2.dta", replace

use "c:\Data\Imf\IMFdata3.dta", clear
drop baltic balkan casia restussr upto1993 ParlXel2 ExecXel2 USODA oecd IMFlag CHRSL1 CHERL1 CHDCL1 CPIL1 CPIL6 CPILSQ CHDCLSQ CHERLSQ AVGCHDC AVGCPI AVGCHER IMFQuota IMFParts IMFnump IMFseatl IMFParl2 IMFdem IMFUSAID IMFUSODA IMFoecd IMFCHRSL IMFCHDCL IMFCPIL1 IMFCPIL6 _st _d _t _t0 IMFecon IMFmil pfall IMFpfall rfall IMFrfall
quietly run c:\Data\Imf\variables.do

stset Govdur, failure( Govfall) id(govid)
streg baltic balkan casia restussr upto1993 interim numpart seatlar Partisan war Executiv FHdem ParlXel2 ExecXel2 IMFlag, dist(w) robust 

predict pfall, hazard
gen IMFpfall = IMFstat*pfall
gen rfall=Partisan*pfall
gen IMFrfall=rfall*IMFstat

matrix b3=e(b)
matrix v3=e(V)
save "c:\Data\Imf\IMFdata3.dta", replace

use "c:\Data\Imf\IMFdata4.dta", clear
drop baltic balkan casia restussr upto1993 ParlXel2 ExecXel2 USODA oecd IMFlag CHRSL1 CHERL1 CHDCL1 CPIL1 CPIL6 CPILSQ CHDCLSQ CHERLSQ AVGCHDC AVGCPI AVGCHER IMFQuota IMFParts IMFnump IMFseatl IMFParl2 IMFdem IMFUSAID IMFUSODA IMFoecd IMFCHRSL IMFCHDCL IMFCPIL1 IMFCPIL6 _st _d _t _t0 IMFecon IMFmil pfall IMFpfall rfall IMFrfall
quietly run c:\Data\Imf\variables.do

stset Govdur, failure( Govfall) id(govid)
streg baltic balkan casia restussr upto1993 interim numpart seatlar Partisan war Executiv FHdem ParlXel2 ExecXel2 IMFlag, dist(w) robust 

predict pfall, hazard
gen IMFpfall = IMFstat*pfall
gen rfall=Partisan*pfall
gen IMFrfall=rfall*IMFstat

matrix b4=e(b)
matrix v4=e(V)
save "c:\Data\Imf\IMFdata4.dta", replace

use "c:\Data\Imf\IMFdata5.dta", clear
drop baltic balkan casia restussr upto1993 ParlXel2 ExecXel2 USODA oecd IMFlag CHRSL1 CHERL1 CHDCL1 CPIL1 CPIL6 CPILSQ CHDCLSQ CHERLSQ AVGCHDC AVGCPI AVGCHER IMFQuota IMFParts IMFnump IMFseatl IMFParl2 IMFdem IMFUSAID IMFUSODA IMFoecd IMFCHRSL IMFCHDCL IMFCPIL1 IMFCPIL6 _st _d _t _t0 IMFecon IMFmil pfall IMFpfall rfall IMFrfall
quietly run c:\Data\Imf\variables.do

stset Govdur, failure( Govfall) id(govid)
streg baltic balkan casia restussr upto1993 interim numpart seatlar Partisan war Executiv FHdem ParlXel2 ExecXel2 IMFlag, dist(w) robust 

predict pfall, hazard
gen IMFpfall = IMFstat*pfall
gen rfall=Partisan*pfall
gen IMFrfall=rfall*IMFstat

matrix b5=e(b)
matrix v5=e(V)
save "c:\Data\Imf\IMFdata5.dta", replace

mat B4=b1\b2\b3\b4\b5
matrix row1=[1,1,1,1,1]
matrix B4mi=(1/5)*([b1\b2\b3\b4\b5]'*row1')
mat V4mi=(v1+v2+v3+v4+v5)/5
mat Sqs=B4-row1'*B4mi'
mat A=Sqs[1, 1...]
mat AA=diag(A)
mat B=Sqs[2, 1...]
mat BB=diag(B)
mat C=Sqs[3, 1...]
mat CC=diag(C)
mat D=Sqs[4, 1...]
mat DD=diag(D)
mat E=Sqs[5, 1...]
mat EE=diag(E)

mat Sqsq=[A*AA\B*BB\C*CC\D*DD\E*EE]'*row1'

mat SE4sq=vecdiag(V4mi)'+(1/4)*Sqsq*(6/5)
mat SE4mi=(vecdiag(cholesky(diag(SE4sq))))'
mat final=[B4mi, SE4mi]
mat colnames final=Coeff StErr
noisily mat list final



